package controlLayer;



import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import modelLayer.*;
/**
 * The test class ControlTEst.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class ControlTest
{
    
    /**
     * Default constructor for test class ControlTEst
     */
    public ControlTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
        
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }

    @Test
    public void CrudDVDTest()
    {
        controlLayer.DVDCtr dVDCtr1 = new controlLayer.DVDCtr();
        // Create
        dVDCtr1.createDVD("TestBarcode1.0", "TestTitle1.0", "TestArtist1.0", "TestPubDate1.0", 1.0);
        // Find
        assertNotNull(dVDCtr1.findDVD("TestBarcode1.0"));              
        // Update
        dVDCtr1.createDVD("TestBarcode2.0", "TestTitle2.0", "TestArtist2.0", "TestPubDate2.0", 2.0);
        DVD dvd1 = dVDCtr1.findDVD("TestBarcode2.0");  
        dVDCtr1.updateDVD(dvd1,"TestBarcode2.1", "TestTitle2.1", "TestArtist2.1", "TestPubDate2.1", 2.1);
        // Delete
        dVDCtr1.createDVD("TestBarcode3.0", "TestTitle3.0", "TestArtist3.0", "TestPubDate3.0", 3.0);
        dVDCtr1.deleteDVD(dVDCtr1.findDVD("TestBarcode3.0"));
    }
    
    @Test
    public void CrudPersonTest()
    {
        controlLayer.PersonCtr personCtr1 = new controlLayer.PersonCtr();
        // Create
        personCtr1.createPerson("TestCpr1.0", "TestName1.0", "TestAddress1.0", "TestPostalCode1.0", "TestCity1.0","TestPhone1.0");
        // Find
        assertNotNull(personCtr1.findPerson("TestCpr1.0"));
        // Update
        personCtr1.createPerson("TestCpr2.0", "TestName2.0", "TestAddress2.0", "TestPostalCode2.0", "TestCity2.0","TestPhone2.0");
        Person person1 = personCtr1.findPerson("TestCpr2.0");
        personCtr1.updatePerson(person1,"TestCpr2.1", "TestName2.1", "TestAddress2.1", "TestPostalCode2.1", "TestCity2.1","TestPhone2.1");
        // Delete
        personCtr1.createPerson("TestCpr3.0", "TestName3.0", "TestAddress3.0", "TestPostalCode3.0", "TestCity3.0","TestPhone3.0");
        personCtr1.deletePerson(personCtr1.findPerson("TestCpr3.0"));
    }
    
    @Test
    public void CrudLoanTest()
    {
        controlLayer.LoanCtr loanCtr1 = new controlLayer.LoanCtr();
        controlLayer.DVDCtr dVDCtr1 = new controlLayer.DVDCtr();
        controlLayer.PersonCtr personCtr1 = new controlLayer.PersonCtr();
        
        // Create
        
        dVDCtr1.createDVD("BarcodeForCopy","TitleForCopy", "ArtistForCopy","PubDateForCopy", 111.11);
        dVDCtr1.createCopy(dVDCtr1.findDVD("BarcodeForCopy"),"TestSerialNumber", "TestPurchaseDate");
        Copy copy1 = dVDCtr1.findCopy(dVDCtr1.findDVD("BarcodeForCopy"),"TestSerialNumber");
        personCtr1.createPerson("CprForLoan","NameForLoan", "AddressForLoan", "PostalCodeForLoan","CityForLoan","PhoneForLoan");
        Person person1 = personCtr1.findPerson("CprForLoan");
        loanCtr1.createLoan(copy1,person1,"TestId1.0", "TestBorrowDate1.0", "TestPeriod1.0","TestState1.0");
        
        // Find
               
        assertNotNull(loanCtr1.findLoan("TestId1.0"));
        
        // Update
        loanCtr1.createLoan(copy1,person1,"TestId2.0", "TestBorrowDate2.0", "TestPeriod2.0","TestState2.0");
        Loan loan1 = loanCtr1.findLoan("TestId2.0");
        loanCtr1.updateLoan(loan1,"TestPeriod2.1");
        
        // Delete
        loanCtr1.createLoan(copy1,person1,"TestId3.0", "TestBorrowDate3.0", "TestPeriod3.0","TestState3.0");
        loanCtr1.deleteLoan(loanCtr1.findLoan("TestId3.0"));
    }
}

